﻿using System;

namespace VisionCloud.Utility.Cached
{
    public class HttpContextCacheProvider
    {

        private static string notSurportHttpStr = StartupServer.CommonLocalizer["YB0274"];

        public static void Set(string key, object obj)
        {
            if (StartupServer.HttpContext == null
                || StartupServer.HttpContext.Items == null)
            {
                return;
            }
            if (StartupServer.HttpContext.Items.ContainsKey(key))
                StartupServer.HttpContext.Items.Remove(key);
            StartupServer.HttpContext.Items.Add(key, obj);
        }

        public static T Get<T>(string key)
        {
            if (StartupServer.HttpContext == null
                || StartupServer.HttpContext.Items == null)
            {
                return default;
            }

            StartupServer.HttpContext.Items.TryGetValue(key, out object result);
            if (result == null)
                return default;
            return (T)result;
        }
    }
}